import React, {Component} from 'react'
import { Redirect } from 'react-router-dom';

class Login11 extends Component {
    constructor(props) {
        super(props);
        this.state = {
            loginflag: false 
          };
    }

    doLogin = (e) => {
        e.preventDefault(); 

        let userName = this.refs.userName.value; 
        let password = this.refs.password.value; 
        console.log(userName, password); 
        
        if(userName == 'admin' & password == '123456'){
            this.setState({
                loginflag: true
            })
        }else {
            alert("登录失败");
        }
    }

    render() {
        if(this.state.loginflag){
            return <Redirect to="/"></Redirect>;
        }else {
            return (
                <div>
                    <form onSubmit={this.doLogin}>
                        <br/><br/><br/>
                        <input type="text" ref="userName"/><br/><br/>
                        <input type="password" ref="password"/><br/><br/>
                        <input type="submit" value="执行登录"/>
                    </form>
                </div>
            )
        }
    }
}

export default Login11;